<template>
  <a-modal
    :title="title"
    width="60%"
    :visible="visible"
    switchFullscreen
    @cancel="handleCancel"
    class="printData"
    :dialog-style="{ top: '5px'}"
  >
    <div style="text-align: center">
      <img style="width: 300px;height: 300px;" :src="qrcodeImgUrl"/>
    </div>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">
        关闭
      </a-button>
<!--      <a-button type="primary" v-print="'#printContent'">-->
<!--        打印二维码-->
<!--      </a-button>-->
    </template>
  </a-modal>
</template>

<script>


import { getAction } from '@api/manage'

export default {
  name: "CustomerQrCode",
  data() {
    return {
      itemData: null,
      qrcodeImgUrl: '',
      title: '机构详情二维码',
      visible: false,
      disableSubmit: false
    }
  },
  methods: {
    async show(cus) {
      this.visible = true;
      // 把站点名字添加到标题
      if (cus.companyName) {
        this.title = `【${cus.companyName}】机构详情二维码`
      } else {
        this.title = '机构详情二维码'
      }
      if(cus && cus.customerNumber){
        let params = {
            customerNumber : cus.customerNumber
        };
        let res = await getAction("/sys/qrCode/get",params);
        if(res && res.success){
          this.qrcodeImgUrl = 'data:image/png;base64,' + res.result
        }
      }
    },
    // 自定义处理数据源
    // forEachDepartData: function(data = [],key) {
    //   let arr = [];
    //   data.forEach((item, index) => {
    //     if(key !== undefined){
    //       item['key'] = `${key}-${index}`;
    //     }else{
    //       item['key'] = `${index}`;
    //     }
    //     if (item.children && item.children.length) {
    //       this.expandedRowKeys.push(item['key']);
    //       item.children = this.forEachDepartData(item.children,index);
    //     }else{
    //       delete item['children'];
    //     }
    //     arr.push(item);
    //   })
    //   return arr;
    // },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.close()
    },
    handleCancel() {
      this.close()
    },
    handleEdit(){

    },
  }

}
</script>

<style scoped>

</style>